home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / gateway.idb / usr / WebFace / Source / 20-NetworkServices / dhcp / dhcp-config.frm.z / dhcp-config.frm
Encoding:
Text File  |  1997-07-30  |  6.4 KB  |  250 lines

  1. #!/usr/bin/perl5
  2. #
  3. # dhcp-config.cgi
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20. # $Id: dhcp-config.frm,v 1.28 1997/06/19 22:24:59 shotes Exp $
  21.  
  22. use Sys::Hostname;
  23. BEGIN { require "/usr/WebFace/lib/CGI.pm"; import CGI; }
  24. require "/usr/OnRamp/lib/OnRamp.pm";
  25. require "/usr/OnRamp/lib/java.pm";
  26.  
  27. $type = $ARGV[0];
  28. if ($type eq "add") { $message = "New subnet added."; }
  29. elsif ($type eq "edit") { $message = "Subnet edited."; }
  30.  
  31. $query = new CGI;
  32.  
  33. $def_config_dir = "/var/dhcp/config";
  34. $netcgi = "dhcp-netconf.cgi";
  35. $title = "DHCP Server Options";
  36.  
  37. $srv_off = system, "/etc/chkconfig", "proclaim_server";
  38. $inetd_cf = "/etc/inetd.conf";
  39. $use_propel = "No";
  40.  
  41. $js =
  42. "type = \"subnet\";
  43. $js_account_main
  44. $js_error_box
  45. $js_ip
  46. function testAdd(form) {
  47.     Ctrl = form.newIP;
  48.     if (Ctrl.value == \"\") {
  49.         errorBox (Ctrl, \"The subnet IP address is required.\");
  50.         return (false);
  51.     }
  52.     if (!testIPaddress(Ctrl.value,false)) {
  53.         errorBox (Ctrl, \"The subnet IP address is invalid.\");
  54.         return (false);
  55.     }
  56.     return (true);
  57. }";
  58.  
  59. open(OUT,"> $dummy"); close(OUT);
  60.  
  61. &getLeases;
  62.  
  63. if ($query->param) {
  64.     $subnet = $query->param('chosen');
  65.     $subnet =~ /([\d.]+)/;
  66.     $subnet = $1;
  67.  
  68.     if ($query->param('add')) {
  69.     $newIP = $query->param('newIP');
  70.     &error("Network address required.") if !$newIP;
  71.     &error("Invalid IP Address.") if &check_ipaddr($query->param('newIP'));
  72.     &addLease($query->param('newIP')); 
  73.     }
  74.     elsif ($query->param('doit')) { 
  75.     $delFile = $query->param('delFile');
  76.     if ($delFile && $delFile ne "Invalid") {    # Too late to check into  
  77.         &delete($delFile);                # quirky CGI.pm bug
  78.         &getLeases;
  79.         $message .= "  Subnet deleted.";
  80.     } else { $message = "No changes made."; }
  81.     }
  82.     elsif ($query->param('edit')) {
  83.     &error("To edit an existing subnet, first select a subnet from the
  84.         list, then click the edit button.") if !$subnet; 
  85.     &edit($subnet); 
  86.     }
  87.     elsif ($query->param('delete')) {
  88.     &error("To delete an existing subnet, first select a subnet from the
  89.         list, then click the delete button.") if !$subnet; 
  90.     print $query->header;
  91.     &js_title_block($title,$js);
  92.     $message = qq|Click "Ok" to save changes.|;
  93.     &generic($subnet); 
  94.     exit 0;
  95.     } elsif (!$type) { $message = "Use buttons to submit form."; }
  96. }
  97.  
  98. print $query->header;
  99.  
  100. $help = $document_root . $ENV{"SCRIPT_NAME"};
  101. $help =~ s/cgi$/hlp/;
  102. exec $help if ($query->param('help') eq "Help");
  103.  
  104. &js_title_block($title,$js);
  105.  
  106. if ($srv_off == 0) { &getFile; }    # chkconfig proclaim_server is on
  107.  
  108. if ($srv_on && $osf) { &getOptions; }
  109.  
  110. &generic;
  111.  
  112. sub error {
  113.     print $query->header;
  114.     &js_title_block($title,$js);
  115.     &error_block($_[0]);
  116.     &generic;
  117.     exit 0;
  118. }    
  119.  
  120. sub addLease {
  121.     $file = $netcgi . "?add$_[0]";
  122.     redirect($file);
  123.     exit(0);
  124. }    
  125.    
  126. sub delete {
  127.     $file = $def_config_dir . "/config." . $_[0];
  128.     unlink $file;
  129. }
  130.  
  131. sub edit {
  132.     $file = $netcgi . "?edit$_[0]";
  133.     redirect($file);
  134.     exit(0);
  135. }
  136.  
  137. sub getFile {
  138.     open(INETD, $inetd_cf) || die "Cannot open $inetd_cf";
  139.     while (<INETD>) {
  140.     if (/^#/) {
  141.         next;
  142.     }
  143.     # bootp dgram udp wait root /usr/etc/dhcp_bootp dhcp_bootp -o <file>
  144.     if (/^bootp/) {
  145.         chop;
  146.         @entlist = split(/\s+/);
  147.         if ($entlist[7] eq "-o") {
  148.         $osf = $entlist[8];
  149.         last;    # Break out of the while loop
  150.         }
  151.     }
  152.     }
  153.     close(INETD);
  154. }
  155.  
  156. sub getOptions {
  157.     $found = 0;
  158.     open(OPTIONS, $osf) || die "Cannot open $osf";
  159.     while(<OPTIONS>) {
  160.     if (/^#/) {
  161.         next;
  162.     }
  163.     chop;
  164.     @optlist = split(/\s+/);
  165.     $i = 0;
  166.     while ($optlist[$i]) {
  167.         if ($optlist[$i] eq "-c") {
  168.         $def_config_dir = $optlist[$i+1];
  169.         $found = 1;
  170.         last;
  171.         }
  172.         $i += 1;
  173.     }
  174.     if ($found == 1) {
  175.         last;
  176.     }
  177.     }
  178.     close(OPTIONS);
  179. }
  180.  
  181. sub getLeases {
  182.     undef @lst;
  183.     opendir(CONFIG, $def_config_dir) || 
  184.         &error("Unable to open directory $def_config_dir");
  185.     while ($name = readdir(CONFIG) ) {
  186.     if ($name =~ /^config\./) {
  187.         $ipa = $name;
  188.         $ipa =~ s/^config\.//;
  189.         if ($ipa ne "Default") { push(@lst,$ipa); }
  190.     }
  191.     }
  192.     closedir(CONFIG);
  193. }
  194.  
  195. sub generic {
  196.     &header_block($title);
  197.  
  198.     print "<i>$message</i>";
  199.  
  200.     print $query->startform("POST", "", "", "NAME=AccountForm", "onSubmit=\"return runSubmit()\"");
  201.  
  202.     if ($_[0]) { print "<input type=hidden name=delFile value=$_[0]>"; }
  203.  
  204.     print "<center><table width=400>";
  205.     print "<tr><th align=left>",$query->submit('add','Add New Subnet',
  206.     'onClick="markAdd()"'),"</th>";
  207.     print "<td>",$query->textfield(-name=>'newIP', -size=>19),"</td></tr>";
  208.  
  209.     if ($_[0]) { 
  210.     undef @locList;
  211.     foreach $arg (@lst) {
  212.         if ($arg ne $_[0]) { push(@locList,$arg); }
  213.     }
  214.     } else { @locList = @lst; }
  215.     print "<tr><th align=left>",$query->submit('edit','Edit Existing Subnet',
  216.     'onClick="markEdit()"'),"</th>";
  217.     print "<td rowspan=2>",&choice_list(*locList,'chosen',20),"</td></tr>";
  218.  
  219.     print "<tr><th align=left>",$query->submit('delete','Delete Existing Subnet','onClick="markDelete()"'),"</th></tr>";
  220.  
  221.     print "</table><br>";
  222.  
  223.     print &js_buttons('doit','Ok','onClick="markOther()"','onClick="markOther()"');
  224.  
  225.     print $query->endform;
  226. }
  227.  
  228. sub old {
  229.     if ($#lst > -1) {
  230.  
  231.     print "<center><table width=300>";
  232.  
  233.     print "<tr><th align=left>Name</th><th>Edit</th><th>Delete</th></tr>";
  234.  
  235.     foreach $arg (@lst) {
  236.         print "<tr><td>",$arg,"</td><td align=center>",$query->submit("edt".$arg,"Edit"),
  237.         "</td><td align=center>",
  238.         "<input type=checkbox name=del$arg value='Delete'>",
  239.         "</td></tr>";
  240.     }
  241.     } else { print "<i><center>No clients currently configured.
  242.                     </center></i>"; }
  243.  
  244.     print "</table></center><br>";
  245.  
  246.     &button_table($query,'doit','Ok','help','Help');
  247.  
  248.     print $query->endform;
  249. }    
  250.